package team.zero.lemon.module.sys.web;

import team.zero.lemon.common.authz.annotation.AuthPassport;
import team.zero.lemon.common.authz.annotation.AuthPermission;
import team.zero.lemon.common.persistence.Page;
import team.zero.lemon.common.security.session.model.Function;
import team.zero.lemon.common.web.BaseController;
import team.zero.lemon.module.sys.service.FunctionService;
import team.zero.lemon.module.sys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by bolin on 2016/5/10.
 */
@Controller
@ResponseBody
@AuthPassport
@RequestMapping(value = "${adminPath}/sys/function", method = {RequestMethod.POST, RequestMethod.GET})
public class FunctionController extends BaseController {
    @Autowired
    private FunctionService functionService;

    @AuthPassport
    @RequestMapping("/query")
    @AuthPermission("sys:function:view")
    public List<Function> findFunction(@RequestBody Function function) {
        return functionService.findFunction(function);
    }

    @AuthPassport
    @RequestMapping("/query/page/parentId")
    @AuthPermission("sys:function:view")
    public Page<Function> findFunctionByParentId(@RequestBody Function function) {
        return functionService.findFunctionByParentId(function);
    }

    @AuthPassport
    @RequestMapping("/save")
    @AuthPermission("sys:function:edit")
    public int SaveFunction(@RequestBody Function function) {
        return functionService.save(function);
    }


    @AuthPassport
    @RequestMapping("/delete/ids")
    @AuthPermission("sys:function:delete")
    public int deleteFunction(@RequestBody Function function) {
        return functionService.deleteLogicMulti(function);
    }

}
